using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FiltronASP.Models;
using FiltronASP.Models.DAO.WIX;
using FiltronASP.Models.DAO.Extensions;
using FiltronASP.Models.DAO.Interfaces.WIX;
using FiltronASP.Models.DAO.Filtron;
using FiltronASP.Models.DAO.Interfaces.Filtron;
using FiltronASP.Helpers.Translations;
using FiltronASP.Helpers.CatalogueHelpers;


namespace FiltronASP.Helpers.AjaxModel
{
    /// <summary>
    /// Klasa pomocnicza do generowania stringa z lista modeli.
    /// </summary>
    public static class sizesHelperFiltron
    {
        public static string generateFiltersBySizes(decimal dimA, decimal dimB, decimal dimC, decimal dimD, decimal dimE,
           decimal dimF, decimal dimG, decimal dimH,
           int dimAdiff, int dimBdiff, int dimCdiff, int dimDdiff, int dimEdiff, int dimFdiff, int dimGdiff, int dimHdiff, string selectedType, string selectedShape, string languageName)
        {
            IFiltronFilterTypeShapeDAO FiltronFilterTypeShapeDAO = new FiltronFilterTypeShapeDAO();
            string toReturn = String.Empty;
            int filterShape = recognizeShapeId(selectedShape);

            IFiltronFilterDAO FiltronFilterDAO = new FiltronFilterDAO();
            IQueryable<FiltronFilter> filtersByDimension = FiltronFilterDAO.FindByDimensions(
                 dimA, dimAdiff,
                 dimB, dimBdiff,
                 dimC, dimCdiff,
                 dimD, dimDdiff,
                 dimE, dimEdiff,
                 dimF, dimFdiff,
                 dimG, dimGdiff,
                 dimH, dimHdiff,
                 filterShape);

          
            toReturn += " <div class=\"col-lg-4 col-md-6 col-sm-6 col-xs-12\">";

            toReturn += " <div class=\"c12p oe oebb\">";

            toReturn += " <div class=\" col-xs-2 no-padding oer\">";
            toReturn += " <p>Filter</p>";
            toReturn += " </div>";
            toReturn += " <div class=\"c10p \">";
            toReturn += " <div class=\"c6p \" > ";
            toReturn += " <div class=\"c6p \" > ";
            toReturn += " <div class=\"c6p oer\" > ";
            toReturn += "<p>A</p>";
            toReturn += " </div> ";
            toReturn += " <div class=\"c6p oer\" > ";
            toReturn += "<p>B</p>";
            toReturn += " </div> ";
            toReturn += " </div> ";
            toReturn += " <div class=\"c6p \" > ";
            toReturn += " <div class=\"c6p oer\" > ";
            toReturn += "<p>C</p>";
            toReturn += " </div> ";
            toReturn += " <div class=\"c6p oer\" > ";
            toReturn += "<p>D</p>";
            toReturn += " </div> ";
            toReturn += " </div> ";
            toReturn += " </div> ";
            toReturn += " <div class=\"c6p \" > ";
            toReturn += " <div class=\"c6p \" > ";
            toReturn += " <div class=\"c6p oer\" > ";
            toReturn += "<p>E</p>";
            toReturn += " </div> ";
            toReturn += " <div class=\"c6p oer\" > ";
            toReturn += "<p>F</p>";
            toReturn += " </div> ";
            toReturn += " </div> ";
            toReturn += " <div class=\"c6p \" > ";
            toReturn += " <div class=\"c6p oer\" > ";
            toReturn += "<p>G</p>";
            toReturn += " </div> ";
            toReturn += " <div class=\"c6p \" > ";
            toReturn += "<p>H</p>";
            toReturn += "</div>";
            toReturn += " </div> ";
            toReturn += " </div> ";
            toReturn += " </div>";

            if (filtersByDimension != null)
            {
                var x = 0;
                foreach (FiltronFilter filter in filtersByDimension)
                {
                    x = x + 1;
                    if (x > 0)
                    {
                        toReturn += "<div class=\"makeFilterActive c12p oe engine-hover oebb\" >";
                        string filterNumber = String.Empty;
                        if (filter.filter_wix_number != null)
                        {
                            filterNumber = filter.filter_wix_number;
                        }
                        if (!(filterNumber.Length > 0))
                        {
                            filterNumber = filter.filter_wix_number_hd;
                        }

                        toReturn += "<div class=\"c12p oe oebb\">";
                        toReturn += " <div class=\" col-xs-2 no-padding oer\">";
                        toReturn += filterNumber;
                        toReturn += " </div>";

                        toReturn += "<div class=\"c10p \">";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_a);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_b);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_c);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_d);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_e);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_f);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";

                        if (filter.filter_dim_g_text != null)
                        {
                            toReturn += filter.filter_dim_g_text;
                        }
                        else
                        {
                            toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_g);
                        }
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_h);
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                    }
                }
            }   //if
            toReturn += "</div>";

            return toReturn;
        }

        public static string generateFiltersBySizesPaginated(decimal dimA, decimal dimB, decimal dimC, decimal dimD, decimal dimE,
            decimal dimF, decimal dimG, decimal dimH,
            int dimAdiff, int dimBdiff, int dimCdiff, int dimDdiff, int dimEdiff, int dimFdiff, int dimGdiff, int dimHdiff, string selectedType, string selectedShape, string languageName, int start, int offset)
        {
            IFiltronFilterTypeShapeDAO FiltronFilterTypeShapeDAO = new FiltronFilterTypeShapeDAO();
            string toReturn = String.Empty;
            int filterShape = recognizeShapeId(selectedShape);


            IFiltronFilterDAO FiltronFilterDAO = new FiltronFilterDAO();
            IQueryable<FiltronFilter> filtersByDimensionsPaginated = FiltronFilterDAO.FindByDimensionsPaginated(
                dimA, dimAdiff,
                dimB, dimBdiff,
                dimC, dimCdiff,
                dimD, dimDdiff,
                dimE, dimEdiff,
                dimF, dimFdiff,
                dimG, dimGdiff,
                dimH, dimHdiff,
                filterShape, start, offset);

            if (start == 0)
            {
                toReturn += " <div class=\"inn\">";

                toReturn += " <div class=\"c12p oe oebb\">";

                toReturn += " <div class=\" col-xs-2 no-padding oer\">";
                toReturn += " <p>Filter</p>";
                toReturn += " </div>";
                toReturn += " <div class=\"c10p \">";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>A</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>B</p>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>C</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>D</p>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>E</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>F</p>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>G</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += "<p>H</p>";
                toReturn += "</div>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " </div>";
                toReturn += " </div>";
            }
            
            var x = start;
            var y = x;
            if (filtersByDimensionsPaginated != null)
            {
              
                foreach (FiltronFilter filter in filtersByDimensionsPaginated)
                {
                    x = x + 1;
                    if (x>0)
                    {
                        toReturn += "<div class=\"c12p oe engine-hover oebb makeFilterActive\" style=\"cursor: pointer\" data-filter=\""+ filter.filter_id +"\" >";
                        string filterNumber = String.Empty; 
                        if (filter.filter_wix_number != null)
                        {
                            filterNumber = filter.filter_wix_number;
                        }
                        if (!(filterNumber.Length > 0))
                        {
                            filterNumber = filter.filter_wix_number_hd;
                        }

                        toReturn += "<div class=\"c12p \">"; /* oe*/
                        toReturn += " <div class=\" col-xs-2 no-padding oer\">";
                        toReturn += filterNumber;
                        toReturn += " </div>";

                        toReturn += "<div class=\"c10p\">";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer \" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_a);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_b);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_c);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_d);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_e);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_f);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";

                        if (filter.filter_dim_g_text != null)
                        {
                            toReturn += filter.filter_dim_g_text;
                        }
                        else
                        {
                            toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_g);
                        }
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_h);
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                    }
                }
            }   //if
            toReturn += "</div>";
            if (x > y)
            {
                toReturn += "<div class=\"col-xs-12 anchor\" style=\"opacity: 0.01;\" id=\"" + languageName + "-" + x + "\">loading</div>";
            }
            return toReturn;
        }
  /*      public static string generateFiltersBySizesPag(decimal dimA, decimal dimB, decimal dimC, decimal dimD, decimal dimE,
            decimal dimF, decimal dimG, decimal dimH,
            int dimAdiff, int dimBdiff, int dimCdiff, int dimDdiff, int dimEdiff, int dimFdiff, int dimGdiff, int dimHdiff, string selectedType, string selectedShape, string languageName, int start, int offset)
        {
            IFiltronFilterTypeShapeDAO FiltronFilterTypeShapeDAO = new FiltronFilterTypeShapeDAO();
            string toReturn = String.Empty;
            int filterShape = recognizeShapeId(selectedShape);

            IFiltronFilterDAO FiltronFilterDAO = new FiltronFilterDAO();
            IQueryable<FiltronFilter> filtersByDimension = FiltronFilterDAO.FindByDimensions(
                 dimA, dimAdiff,
                 dimB, dimBdiff,
                 dimC, dimCdiff,
                 dimD, dimDdiff,
                 dimE, dimEdiff,
                 dimF, dimFdiff,
                 dimG, dimGdiff,
                 dimH, dimHdiff,
                 filterShape);

            if (start == 0)
            {

                toReturn += " <div class=\"col-lg-4 col-md-6 col-sm-6 col-xs-12\">";

                toReturn += " <div class=\"c12p oe oebb\">";

                toReturn += " <div class=\" col-xs-2 no-padding oer\">";
                toReturn += " <p>Filter</p>";
                toReturn += " </div>";
                toReturn += " <div class=\"c10p \">";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>A</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>B</p>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>C</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>D</p>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>E</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>F</p>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += " <div class=\"c6p oer\" > ";
                toReturn += "<p>G</p>";
                toReturn += " </div> ";
                toReturn += " <div class=\"c6p \" > ";
                toReturn += "<p>H</p>";
                toReturn += "</div>";
                toReturn += " </div> ";
                toReturn += " </div> ";
                toReturn += " </div>";
            }
            if (filtersByDimension != null)
            {
                var x = 0;
                foreach (FiltronFilter filter in filtersByDimension)
                {
                    x = x + 1;
                    if (x<20)
                    {
                        toReturn += "<div class=\"c12p oe engine-hover oebb\" onclick=\"makeFilterActive(this, '" + languageName + "')\" id=\"" + filter.filter_id + "\">";
                        string filterNumber = String.Empty;
                        if (filter.filter_wix_number != null)
                        {
                            filterNumber = filter.filter_wix_number;
                        }
                        if (!(filterNumber.Length > 0))
                        {
                            filterNumber = filter.filter_wix_number_hd;
                        }

                        toReturn += "<div class=\"c12p oe oebb\">";
                        toReturn += " <div class=\" col-xs-2 no-padding oer\">";
                        toReturn += filterNumber;
                        toReturn += " </div>";

                        toReturn += "<div class=\"c10p \">";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_a);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_b);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_c);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_d);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_e);
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p oer\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_f);
                        toReturn += "</div> ";
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p \" > ";
                        toReturn += "<div class=\"c6p oer\" > ";

                        if (filter.filter_dim_g_text != null)
                        {
                            toReturn += filter.filter_dim_g_text;
                        }
                        else
                        {
                            toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_g);
                        }
                        toReturn += "</div> ";
                        toReturn += "<div class=\"c6p\" > ";
                        toReturn += SingleFilterHelper.parseFilterSizes(filter.filter_dim_h);
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                        toReturn += "</div>";
                    }
                }
            }   //if
          
                toReturn += "</div>";
          
            return toReturn;
        }
*/
        private static int recognizeShapeId(string selectedShape)
        {
            int shapeId = 0;
            if (selectedShape == "air1") shapeId = 159;
            if (selectedShape == "air2") shapeId = 160;
            if (selectedShape == "air3") shapeId = 161;
            if (selectedShape == "oil1") shapeId = 163;
            if (selectedShape == "oil2") shapeId = 162;
            if (selectedShape == "fuel1") shapeId = 165;
            if (selectedShape == "fuel2") shapeId = 164;
            if (selectedShape == "fuel3") shapeId = 166;
            if (selectedShape == "fuel4") shapeId = 167;
            if (selectedShape == "cabin1") shapeId = 169;
            if (selectedShape == "cabin2") shapeId = 168;
            return shapeId;
        }

    }
}
